require 'active_support'
require 'rexml/document'
require 'find'
	
class MyListener
	include REXML

	def initialize
		@removeTags = ["PublicKeyToken"]	
	end
	
	def tag_start(*args)
		
		puts args 
		puts @removeTags
		puts @removeTags.find{|e| e == args}
		#if @removeTags.find{|e| e == args}
						
		#puts "tag_start: #{args.map {|x| x.inspect}.join(', ')}"
	end
	
	def text(data)
		#return if data =~ /^\w*$/     # whitespace only
		#abbrev = data[0..40] + (data.length > 40 ? "..." : "")
		#puts "  text   :   #{abbrev.inspect}"
	end
	
	def tag_end(*args)
		#puts "end_tag: #{args} " 
	end
	
end

class StrongNameRemover
	include REXML

	def remove
		Find.find('./') do |file| 
			if(file.ends_with?('.csproj'))
				process_file file
			end
		end
	end	
	
	def process_file(file)
		puts "processing file: " + file
		
		openFile = File.open(file)
			
		#list = MyListener.new
		#Document.parse_stream(openFile, list)
		
		doc = Document.new(openFile)
		propertyGroups = XPath.match(document, '/Project/PropertyGroup/AssemblyOriginatorKeyFile')  
    	assert(propertyGroups.find { | propertyGroup | puts propertyGroup.text })  
		
		#return if doc.root == nil
		#process_xml doc
		
	end
	
	def process_xml(doc)
		
		doc.elements.each("PropertyGroup") do |e| 
			puts e 
			puts "----------------"
		end
		
	end
	
end

rm = StrongNameRemover.new
rm.remove